package com.wecloud.core.controller;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.wecloud.core.exception.WeException;


public abstract class WeCloudCoreConller implements ApplicationContextAware {
	@Autowired 
	private ApplicationContext context;
	Logger logger = LoggerFactory.getLogger(WeCloudCoreConller.class);
	/**
	 * 处理结果
	 * @param msg
	 * @param response
	 */
	protected void responseMsg(String msg, HttpServletResponse response) {
		try {
			response.setContentType("application/json; charset=utf-8");
			PrintWriter out = response.getWriter();
			out.write(msg);
		} catch (Exception e) {
			logger.error("[处理返回报文时发生错误！]", e);
		}
	}
	protected abstract void handler(HttpServletRequest req, HttpServletResponse resp)throws WeException;
	
	@Override
	public void setApplicationContext(ApplicationContext arg0) throws BeansException {
		context = arg0;		
	}
	protected Object getTransAction(String name) throws BeansException  
    {  
        return context.getBean(name);  
    }
}
